package gold.digger;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC769 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public int maxChunksToSorted(int[] arr) {
            //当遍历到第i个位置时，如果可以切分为块，那前i个位置的最大值一定等于i。
            //否则，一定有比i小的数划分到后面的块，那块排序后，一定不满足升序。
            int res = 0, max = 0;
            for (int i = 0; i < arr.length; i++) {
                max = Math.max(max, arr[i]);//统计前i个位置的最大元素
                if (max == i) res++;
            }
            return res;
        }
    }

    public void run() {
        Solution solution = new Solution();
        List<Integer> list = new ArrayList<>();
        System.out.println(solution.toString());
    }

    public static void main(String[] args) throws Exception {
        LC769 an = new LC769();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
